package com.sesxh.project.knowledge.router;

import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sesxh.frame.core.data.DataSet;
import com.sesxh.frame.web.controller.BaseController;
import com.sesxh.project.knowledge.biz.model.Favorite;
import com.sesxh.project.knowledge.biz.service.IFavoriteService;
@Controller 
@RequestMapping("/knowledge/favorite")
public class FavoriteController implements BaseController {

	
	@Autowired
	private IFavoriteService favoriteService;
	
    @RequestMapping(value="/loadFavoriteDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadFavoriteDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  favoriteService.loadFavoriteDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
    @RequestMapping(value="/createFavorite", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createFavorite(Favorite favorite){
		favoriteService.createFavorite(favorite);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadFavorite", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadFavorite(Long id){
		Optional<Favorite> ops = favoriteService.loadFavoriteById(id);
		return ajaxQuery("favorite",ops);
    }
	
    @RequestMapping(value="/updateFavorite", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateFavorite(Favorite favorite){
		favoriteService.updateFavorite(favorite);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/deleteFavorite", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteFavorite(Long id){
		favoriteService.deleteFavorite(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

}